define(["jquery", "easy-admin"], function ($, ea) {
    var form = layui.form;
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'calculation.calculation/index',
        add_url: 'calculation.calculation/add',
        edit_url: 'calculation.calculation/edit',
        delete_url: 'calculation.calculation/delete',
        export_url: 'calculation.calculation/export',
        modify_url: 'calculation.calculation/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id', search: false},
                    {field: 'title', title: '标题'},
                    {field: 'image', title: '图片', templet: ea.table.image, search: false},
                    {field: 'produce', title: '产出'},
                    {field: 'stock', title: '算力库存'},
                    {field: 'status', search: 'select', selectList: {"1":"启用","2":"禁用"}, title: '状态', templet: ea.table.switch},
                    {field: 'is_recommend', title: '推荐', width: 85, selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch},
                    {field: 'create_time', title: '添加时间', search: false},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
            form.on('radio(type)', function(data){
                if(data.value == 2){
                    $('#datys').show();
                }else{
                    $('#datys').hide();
                }
            });
        },
        edit: function () {
            ea.listen();
            form.on('radio(type)', function(data){
                if(data.value == 2){
                    $('#datys').show();
                }else{
                    $('#datys').hide();
                }
            });
        },
    };
    return Controller;
});